<?php

class Adept_Validate_Size extends Adept_Validate_Abstract implements Adept_Validate_IValidator
{

    protected $minLength;
    protected $maxLength;
    
    public function __construct()
    {
    }

    public function getMinLength()
    {
        return $this->minLength;
    }

    public function setMinLength($minLength)
    {
        $this->minLength = $minLength;
    }

    public function getMaxLength()
    {
        return $this->maxLength;
    }

    public function setMaxLength($maxLength)
    {
        $this->maxLength = $maxLength;
    }

    public function validate($sender, $value)
    {
        if (!is_null($this->minLength) && strlen($value) < $this->minLength) {
            $title = ($sender instanceof Adept_Component_Control) ? $sender->getTitle() : '';
            throw new Adept_Validate_Exception('SIZE_TOO_SMALL', 0, 
                array(
                    'min' => $this->minLength,
                    'field' => $title,
                )
            );
        } else if (!is_null($this->maxLength) && strlen($value) > $this->maxLength) {
            $title = ($sender instanceof Adept_Component_Control) ? $sender->getTitle() : '';
            throw new Adept_Validate_Exception('SIZE_TOO_BIG', 0, 
                array(
                    'max' => $this->maxLength,
                    'field' => $title,
                )
            );
        }
        return ;
    }

}